﻿using Luna小店.DTO;
using Luna小店.service;
using Luna小店.UC.款式尺寸;
using Luna小店.UC.款式管理.service;
using Luna小店.UC.门店下单.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luna小店.UC.款式管理
{
    public partial class Frm款式维护预览 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public 款式图片一览Dto 款式基本信息 { get; set; }
        public string styleId;
        public Frm款式维护预览()
        {
            InitializeComponent();
            this.comboBoxData();
            this.textBoxSTYLE_FIT_CD.Text = "FIT_BODY_TYPE-";
            this.款式基本信息 = new 款式图片一览Dto();
        }
        public Frm款式维护预览(String styleid)
        {
            InitializeComponent();
            this.styleId = styleid;
            this.款式基本信息 = StyleService.getStyleById(styleid);
            this.comboBoxData();
            this.comboBoxOld();
            this.textBoxstyleid.Text = styleid;
            this.pictureBox款式图片.LoadAsync(款式Service.get款式图(this.styleId));
        }

        private void Frm款式维护预览_Load(object sender, EventArgs e)
        {

        }
        private void comboBoxData()
        {
            this.comboBoxSTYLE_CATEGORY_CD.DataSource = StyleService.getSTYLE_CATEGORY_CD();
            this.comboBoxSTYLE_DRESS_CATEGORY.DataSource = StyleService.getSTYLE_DRESS_CATEGORY();
            this.comboBoxSTYLE_DESIGN_TYPE.DataSource = StyleService.getSTYLE_DESIGN_TYPE();
            this.comboBoxSTYLE_PUBLISH_CATEGORY_CD.DataSource = StyleService.getSTYLE_PUBLISH_CATEGORY_CD();
            this.comboBoxSYTLE_SEASON.DataSource = StyleService.getSYTLE_SEASON();
            this.comboBoxSTYLE_MAKE_TYPE.DataSource = StyleService.getSTYLE_MAKE_TYPE();
            this.comboBoxSTYLE_SIZE_GROUP_CD.DataSource = StyleService.getSTYLE_SIZE_GROUP_CD();
            this.comboBoxSTYLE_CATEGORY_CD.SelectedIndex = -1;
            this.comboBoxSTYLE_DRESS_CATEGORY.SelectedIndex = -1;
            this.comboBoxSTYLE_DESIGN_TYPE.SelectedIndex = -1;
            this.comboBoxSTYLE_PUBLISH_CATEGORY_CD.SelectedIndex = -1;
            this.comboBoxSYTLE_SEASON.SelectedIndex = -1;
            this.comboBoxSTYLE_MAKE_TYPE.SelectedIndex = -1;
            this.comboBoxSTYLE_SIZE_GROUP_CD.SelectedIndex = -1;
            this.comboBoxSTYLE_SIZE_CD.SelectedIndex = -1;
        }
        private void comboBoxOld()
        {
            this.comboBoxSTYLE_CATEGORY_CD.SelectedValue = this.款式基本信息.STYLE_CATEGORY_CD;
            this.comboBoxSTYLE_DRESS_CATEGORY.SelectedValue = this.款式基本信息.STYLE_DRESS_CATEGORY;
            this.comboBoxSTYLE_DESIGN_TYPE.SelectedValue = this.款式基本信息.STYLE_DESIGN_TYPE;
            this.comboBoxSTYLE_PUBLISH_CATEGORY_CD.SelectedValue = this.款式基本信息.STYLE_PUBLISH_CATEGORY_CD;
            this.comboBoxSYTLE_SEASON.SelectedValue = this.款式基本信息.SYTLE_SEASON;
            this.comboBoxSTYLE_MAKE_TYPE.SelectedValue = this.款式基本信息.STYLE_MAKE_TYPE;
            this.comboBoxSTYLE_SIZE_GROUP_CD.SelectedValue = this.款式基本信息.STYLE_SIZE_GROUP_CD;
            try
            {
                this.comboBoxSTYLE_SIZE_CD.SelectedValue = this.款式基本信息.STYLE_SIZE_CD;
            }
            catch{ }
            this.textBoxSTYLE_DESIGN_PRICE.Text = this.款式基本信息.STYLE_DESIGN_PRICE;
            this.textBoxSTYLE_MATERIAL_NUMBER.Text = this.款式基本信息.STYLE_MATERIAL_NUMBER;
            this.textBoxSYTLE_YEAR.Text = this.款式基本信息.SYTLE_YEAR;
            this.textBoxSTYLE_NAME_CN.Text = this.款式基本信息.STYLE_NAME_CN;
            this.textBoxSTYLE_FIT_CD.Text = this.款式基本信息.STYLE_FIT_CD;
        }
        private void comboBoxSTYLE_SIZE_GROUP_CD_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string[] sizecds = this.comboBoxSTYLE_SIZE_GROUP_CD.SelectedValue.ToString().Split('-');
                this.comboBoxSTYLE_SIZE_CD.DataSource = StyleService.getSTYLE_SIZE_CD(sizecds[1]);
            }
            catch { }
        }

        private void Frm款式维护预览_Activated(object sender, EventArgs e)
        {
            object ob;
            ob = this.comboBoxSTYLE_MAKE_TYPE.SelectedItem;
            ob = this.comboBoxSTYLE_MAKE_TYPE.SelectedValue;
            ob = this.comboBoxSTYLE_MAKE_TYPE.SelectedText;
            ob = this.comboBoxSTYLE_MAKE_TYPE.DisplayMember;
        }

        private void barButtonItem基本信息_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.款式基本信息.build款式更新(
            this.comboBoxSTYLE_CATEGORY_CD.SelectedValue.ToString(),
            this.comboBoxSTYLE_DRESS_CATEGORY.SelectedValue.ToString(),
            this.comboBoxSTYLE_DESIGN_TYPE.SelectedValue.ToString(),
            this.comboBoxSTYLE_PUBLISH_CATEGORY_CD.SelectedValue.ToString(),
            this.comboBoxSYTLE_SEASON.SelectedValue.ToString(),
            this.comboBoxSTYLE_MAKE_TYPE.SelectedValue.ToString(),
            this.comboBoxSTYLE_SIZE_GROUP_CD.SelectedValue.ToString(),
            this.comboBoxSTYLE_SIZE_CD.SelectedValue.ToString(),
            this.textBoxSTYLE_DESIGN_PRICE.Text.Trim(),
            this.textBoxSTYLE_MATERIAL_NUMBER.Text.Trim(),
            this.textBoxSYTLE_YEAR.Text.Trim(),
            this.textBoxSTYLE_NAME_CN.Text.Trim(),
            this.textBoxSTYLE_FIT_CD.Text.Trim());
            if (String.IsNullOrEmpty(this.款式基本信息.SYS_STYLE_ID))
            {
                if(this.款式基本信息.CreateStyle()==true)
                {
                    MessageBox.Show("新增成功");
                }
                else
                {
                    MessageBox.Show("新增失败");
                }
            }
            else
            {
                if (this.款式基本信息.UpdataStyle() == true)
                {
                    MessageBox.Show("更新成功");
                }
                else
                {
                    MessageBox.Show("更新失败");
                }
            }
        }

        private void barButtonItem设计点_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new Frm款式维护设计点导入(this.款式基本信息).ShowDialog();
        }

        private void barButtonItem尺寸_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            new Frm尺寸(this.款式基本信息.SYS_STYLE_ID).ShowDialog();
        }

        private void pictureBox款式图片_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "gif,jpg,png|*.gif;*.jpg;*.png;*.jpeg";
            ofd.Title = "请选择图片文件";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                String str = 款式Service.上传款式图(this.styleId, ofd);
                this.pictureBox款式图片.LoadAsync(款式Service.get款式图(this.styleId));
            }
        }
    }
}
